home *** CD-ROM | disk | FTP | other *** search
/ Photography Workshop / PhotoWorkShop.iso / pc / Content / Find / Find.cst / 00001_Find Script.ls next >
Encoding:
Text File  |  2002-04-15  |  12.7 KB  |  381 lines

  1. property ancestor
  2. property EntryChannel
  3. property TopicsDisplay
  4. property DestinationsDisplay
  5. property TopicsSlider, GoToSlider
  6. property GoToButton
  7. property WorkshopList
  8. property Destination
  9. property currentKey
  10. property currentTopic
  11. property topicIndex, workshopIndex
  12. property TopicsHilite, GoToHilite
  13. property FindCommandList
  14. property IDToNameMapping
  15. property theFindList
  16. property longNameMapping
  17. global debugging
  18.  
  19. on Birth me, theChannelObject, theName, thePageInfo
  20.   set the ancestor of me to Birth( script "Master Page Template", theChannelObject, theName, thePageInfo, true, true )
  21.   
  22.   set GoToButton to FindButton( me, "Goto" )
  23.   
  24.   set TopicsRect to FindButton( me, "Topics" )
  25.   set the immediate of TopicsRect to true
  26.   
  27.   set DestsRect to FindButton( me, "Dests" )
  28.   set the immediate of DestsRect to true
  29.   
  30.   set TopicsHilite to FindDisplay( me, "TopicsHilite" )
  31.   SetCastName( TopicsHilite, "TopicsHilite" )
  32.   
  33.   set GoToHilite to FindDisplay( me, "GoToHilite" )
  34.   SetCastName( GoToHilite, "GoToHilite" )
  35.   
  36.   set WorkshopList to []
  37.   set Destination to ""
  38.   set currentKey to ""
  39.   set currentTopic to ""
  40.   set TopicIndex to 0
  41.   
  42.   set TopicsSlider to FindButton( me, "TopicsSlider" )
  43.   set the trackable of TopicsSlider to true
  44.   set the trackRect of topicsSlider to rect( 439, 156, 439, 232 )
  45.   
  46.   set GoToSlider to FindButton( me, "GoToSlider" )
  47.   set the trackable of GoToSlider to true
  48.   set the trackRect of GoToSlider to rect( 439, 321, 439, 397 )
  49.   
  50.   set theCluster to GetAt( the ButtonList of me, 3 )
  51.   repeat with i = 1 to 4
  52.     set thisButton to GetAt( the buttonlist of theCluster, i )
  53.     --put "setting button" && the name of thisButton && "to true"
  54.     set the repeatable of thisButton to true
  55.     set the repeatrate of thisButton to 5
  56.   end repeat
  57.   
  58.   set PageTopics to FindButton( me, "PageTopics" )
  59.   set the repeatable of PageTopics to true
  60.   set the repeatrate of PageTopics to 5
  61.   set PageGoto to FindButton( me, "PageGoTo" )
  62.   set the repeatable of PageGoto to true
  63.   set the repeatrate of PageGoto to 5
  64.   
  65.   set EntryChannel to FindDisplay( me, "EntryChannel" )
  66.   set TopicsDisplay to FindDisplay( me, "TopicsChannel" )
  67.   set DestinationsDisplay to FindDisplay( me, "DestinationsChannel" )
  68.   
  69.   if the channel of TopicsDisplay <> 8 or the channel of DestinationsDisplay <> 9 then
  70.     alert( "Entry, Topics and Destinations Channels not at 7, 8 and 9 --" && the channel of TopicsDisplay && the channel of DestinationsDisplay )
  71.     return
  72.   end if
  73.   
  74.   set the puppet of sprite 7 to false
  75.   set the puppet of sprite 8 to false
  76.   set the puppet of sprite 9 to false
  77.   
  78.   -- jump to a frame that contains scrolling text sprites
  79.   -- Director won't let us puppet scrolling text boxes into sprites occupied by bitmaps
  80.   go to frame "find"
  81.   
  82.   SetCastName( EntryChannel, "Entry" )
  83.   move( EntryChannel, point( 170, 78 ) )
  84.   setink( EntryChannel, #Transparent )
  85.   Set the editable of sprite the channel of entryChannel to true
  86.   set the text of cast "Entry" of castlib "Shared" to ""
  87.   set the font of member "Entry" of castlib "Shared" to "Geneva"
  88.   set the fontsize of member "Entry" of castlib "Shared" to 12
  89.   set the text of cast "Destinations" of castlib "Shared" to " "
  90.   
  91.   set longNameMapping to value( the text of cast "longnames" of castlib "Find" )
  92.   if voidp( longNameMapping ) then
  93.     beep 2
  94.     put "bad longNameMapping"
  95.   end if
  96.   
  97.   ScrollTo( "Topics", 0 )
  98.   ScrollTo( "Destinations", 0 )
  99.   
  100.   LoadList me
  101.   
  102.   Show me
  103.   return me
  104. end
  105.  
  106. on Leave me
  107.   set the puppet of sprite 7 to true
  108.   set the puppet of sprite 8 to true
  109.   set the puppet of sprite 9 to true
  110.   Set the editable of sprite the channel of entryChannel to false
  111.   go to frame 2
  112.   Leave the ancestor of me
  113. end
  114.  
  115.  
  116. on ConstrainScroll theCastName, theTop, theSpriteHeight
  117.   if theTop < 0 then set theTop to 0
  118.   if ( the height of cast theCastName - thetop ) < theSpriteHeight then
  119.     set thetop to the height of cast theCastName - theSpriteHeight
  120.   end if
  121.   return theTop
  122. end
  123.  
  124. on ScrollTo theCastName, theTop
  125.   set the scrolltop of cast theCastName of castlib "Shared" to theTop
  126. end
  127.  
  128. on UpdateSlider theSlider, theChannel, theCastName
  129.   set workingHeight to the height of cast theCastName of castlib "Shared" - the height of sprite theChannel
  130.   set thePerc to float( float(the scrolltop of cast theCastName of castlib "Shared") / float( workingHeight ) )
  131.   if thePerc > 1.0 then
  132.     set thePerc to 1
  133.   end if
  134.   set theRect to the trackrect of theSlider
  135.   set barHeight to the bottom of theRect - the top of theRect
  136.   --put thePerc && barHeight * thePerc
  137.   
  138.   set thePoint to duplicate(the location of theSlider)
  139.   setat( thePoint, 2, integer(barHeight * thePerc) + the top of the trackrect of theSlider )
  140.   --put "updating slider to point" && thePoint
  141.   Move( theSlider, thePoint )
  142. end
  143.  
  144. on DoSlider theSlider, theChannel, theCastName
  145.   set theLocV to GetAt( the location of theSlider, 2 )
  146.   set theRect to the trackrect of theSlider
  147.   set thePerc to float( float( theLocV - the top of theRect ) / float( the bottom of theRect - the top of theRect ) )
  148.   set workingHeight to the height of cast theCastName of castlib "Shared" - the height of sprite theChannel
  149.   --put thePerc && workingHeight * thePerc
  150.   ScrollTo( theCastName, workingHeight * thePerc )
  151. end
  152.  
  153. on ScrollAndUpdate me, theCastName, theslider, theChannel, direction
  154.   Hide( TopicsHilite )
  155.   UpdateStage
  156.   ScrollByLine( cast theCastName of castlib "Shared", direction )
  157.   if currenttopic <> "" then
  158.     ShowTopicsHilite( me, topicIndex )
  159.   end if
  160.   UpdateSlider( theslider, theChannel, theCastName )
  161. end
  162.  
  163.  
  164. on ShowHilite me, theCastName, Index, theChannel, theHilite
  165.   set theScrollTop to the scrolltop of cast theCastName of castlib "Shared"
  166.   set theV to linePosToLocV(member theCastName of castlib "Shared", Index)
  167.   if theV >= theScrollTop and theV < theScrollTop + 125 then
  168.     set theV to theV + ( the top of sprite theChannel - theScrollTop )
  169.     set thePoint to Point( 296, theV )
  170.   else
  171.     set thePoint to Point( 296, -1000 )
  172.   end if
  173.   Move( theHilite, thePoint )
  174. end      
  175.  
  176. on ShowTopicsHilite me
  177.   ShowHilite( me, "Topics", TopicIndex, the channel of TopicsDisplay, TopicsHilite )
  178. end      
  179.  
  180. on ShowGoToHilite me
  181.   ShowHilite( me, "Destinations", WorkshopIndex, the channel of DestinationsDisplay, GoToHilite )
  182. end      
  183.  
  184. on SelectWorkshop me
  185.   ShowGoToHilite me
  186.   SetState( GoToButton, "Enabled", true )
  187. end
  188.  
  189. on ShowWorkshops me
  190.   set Workshoplist to GetAProp( theFindList, CurrentTopic )
  191.   --put "workshoplist" && workshoplist
  192.   set WorkshopIndex to 0
  193.   Set Desination to ""
  194.   set workshops to ""
  195.   set FindCommandList to []
  196.   set the text of cast "Destinations" of castlib "Shared" to ""
  197.   if not voidp( workshoplist ) then
  198.     Hide( GoToHilite )
  199.     repeat with i = 1 to count(Workshoplist)
  200.       set shortName to GetPropAt(Workshoplist, i)
  201.       --put "shortname" && shortname
  202.       set NameInfo to getprop( longnamemapping, shortname )
  203.       set longName to getat( nameinfo, 2 )
  204.       set GotoName to getat( nameinfo, 1 )
  205.       put longName & RETURN after workshops
  206.       set thisWorkshopCommand to [#GoToPage, GotoName]
  207.       add(FindCommandList, [thisWorkshopCommand] )
  208.       set teachmelist to getat(Workshoplist, i)
  209.       --put "teachmelist" && teachmelist
  210.       repeat with j = 1 to count(teachmelist)
  211.         set teachMeID to getat(teachmelist, j)
  212.         --put teachMeId
  213.         set teachMename to GetaProp( IDToNameMapping, teachMeID )
  214.         if teachMeName <> 0 then
  215.           --put teachMeId && teachMename
  216.           add(FindCommandList, [thisWorkshopCommand, [#CommandList, teachMeID]] )
  217.           put "  " & teachMeName & RETURN after workshops
  218.         else
  219.           if debugging = true then beep
  220.           --put "cant find teach me id" && teachMeID && "in workshop" && shortName
  221.         end if
  222.       end repeat
  223.     end repeat
  224.     
  225.     set the text of cast "Destinations" of castlib "Shared" to workshops
  226.     set the font of member cast "Destinations" of castlib "Shared" to "Geneva"
  227.     set the fontsize of member cast "Destinations" of castlib "Shared" to 12
  228.     
  229.     if count(workshoplist) = 1 then
  230.       set workshopindex to 1
  231.       SelectWorkshop me
  232.     else
  233.       SetState( GoToButton, "Disabled", true )
  234.     end if
  235.     
  236.   else
  237.     SetState( GoToButton, "Disabled", true )
  238.   end if
  239. end
  240.  
  241. on ScrollByPageAndUpdate me, theslider, thechannel, thecastname, theamount
  242.   Hide( TopicsHilite )
  243.   scrollByPage( member thecastname of castlib "Shared", theamount )
  244.   if currenttopic <> "" then
  245.     ShowTopicsHilite( me, topicIndex )
  246.   end if
  247.   UpdateSlider( theslider, thechannel, thecastname )
  248. end
  249.  
  250. on ChangePage me, theElementID, theValue1, theValue2
  251.   
  252.   ChangePage( the ancestor of me, theElementID, theValue1, theValue2 )
  253.   
  254.   case theElementID of
  255.     "TopicsUp":
  256.       ScrollAndUpdate( me, "Topics", topicsslider, the channel of TopicsDisplay, -1 )
  257.     "TopicsDown":
  258.       ScrollAndUpdate( me, "Topics", topicsslider, the channel of TopicsDisplay, 1 )
  259.     "GoToUp":
  260.       ScrollAndUpdate( me, "Destinations", gotoslider, the channel of DestinationsDisplay, -1 )
  261.     "GoToDown":
  262.       ScrollAndUpdate( me, "Destinations", gotoslider, the channel of DestinationsDisplay, 1 )
  263.       
  264.     "TopicsSlider":
  265.       DoSlider( topicsslider, the channel of TopicsDisplay, "Topics" )
  266.       ShowTopicsHilite me, topicIndex
  267.       
  268.     "GoToSlider":
  269.       DoSlider( GoToSlider, the channel of DestinationsDisplay, "Destinations" )
  270.       
  271.     "TopicsHit":
  272.       set TopicIndex to the mouseline 
  273.       set CurrentTopic to line TopicIndex of the text of cast "Topics" of castlib "Shared"
  274.       set the text of cast "Entry" of Castlib "Shared" to CurrentTopic
  275.       set the selstart to 0
  276.       set the selend to the number of chars in CurrentTopic
  277.       
  278.       ShowTopicsHilite me
  279.       ShowWorkshops me
  280.       
  281.     "PageTopics":
  282.       if the mousev > the bottom of the buttonrect of topicsslider then
  283.         scrollByPageAndUpdate( me, topicsslider, the channel of TopicsDisplay, "Topics", 1 )
  284.       else
  285.         scrollByPageAndUpdate( me, topicsslider, the channel of TopicsDisplay, "Topics", -1 )
  286.       end if
  287.       
  288.     "PageGoTo":      
  289.       if the mousev > the bottom of the buttonrect of gotoslider then
  290.         scrollByPageAndUpdate( me, gotoslider, the channel of DestinationsDisplay, "Destinations", 1 )
  291.       else
  292.         scrollByPageAndUpdate( me, gotoslider, the channel of DestinationsDisplay, "Destinations", -1 )
  293.       end if
  294.       
  295.     "DestsHit":
  296.       set WorkshopIndex to the mouseline
  297.       SelectWorkshop( me )
  298.       
  299.     "Done":
  300.       QueueCommand( [[#GoBack]] )
  301.       
  302.     "GoTo":
  303.       if the runmode = "author" then alert string(FindCommandList)  --MACK 04.15.02
  304.       if the runmode = "author" then alert string(workshopindex)  --MACK 04.15.02
  305.       
  306.       if workshopindex > count(FindCommandList) or workshopindex = -1 then --MACK 04.15.02
  307.         nothing --MACK 04.15.02
  308.       else --MACK 04.15.02
  309.         put( GetAt(FindCommandList, workshopindex) )
  310.         QueueCommand( GetAt(FindCommandList, workshopindex) ) 
  311.       end if --MACK 04.15.02
  312.       
  313.   end case
  314. end
  315.  
  316. on PageIdle me
  317.   PageIdle the ancestor of me
  318.   
  319.   set theKey to the text of cast "entry" of castlib "Shared"
  320.   if theKey <> CurrentKey then
  321.     --set theKey to UpShift( theKey )
  322.     put theKey
  323.     set currentkey to theKey
  324.     
  325.     set topicindex to FindPosNear( theFindList, theKey )
  326.     if topicIndex > count( theFindList ) then set topicindex to count( theFindList )
  327.     set matchword to GetPropAt( theFindList, topicindex )
  328.     
  329.     --put "found" && TopicIndex && MatchWord
  330.     
  331.     if TopicIndex > 0 and currentTopic <> MatchWord then
  332.       set currentTopic to MatchWord
  333.       
  334.       -- scroll selection to center of topics
  335.       set theV to linePosToLocV(member "Topics" of castlib "Shared", TopicIndex)
  336.       --put "index" && TopicIndex && "locv" && theV
  337.       ScrollTo( "topics", ConstrainScroll( "topics", theV - ( 4 * lineheight(cast "topics" of castlib "Shared", 1) ), 125 ) )
  338.       UpdateSlider( topicsSlider, the channel of TopicsDisplay, "Topics" )
  339.       
  340.       -- show the hilite at the proper location
  341.       ShowTopicsHilite( me, TopicIndex )
  342.       ShowWorkshops me
  343.       
  344.       return
  345.     end if
  346.     
  347.   end if
  348. end
  349.  
  350. on LoadList me
  351.   set tempstring1 to the text of cast "master1" of castlib "Find"
  352.   set tempString2 to the text of cast "master2" of castlib "Find"
  353.   put tempString2 after tempString1
  354.   
  355.   set theFindList to value(tempString1)
  356.   
  357.   set tempstring1 to ""
  358.   set tempstring2 to ""
  359.   if not listp(theFindList) then
  360.     beep 3
  361.     put "bad find list"
  362.   end if
  363.   sort theFindList
  364.   
  365.   set IDtoNameMapping to value(the text of cast "IDToName" of castlib "Find")
  366.   if not listp(IDtoNameMapping) then
  367.     beep
  368.     put "bad ID To Name Mapping list"
  369.   end if
  370.   sort( IDtoNameMapping )
  371. end
  372.  
  373. on ShowFindList
  374.   repeat with i = 1 to count(theFindList)
  375.     set thisKeyword to GetPropAt(theFindList, i)
  376.     set thisWorkshopList to GetAt(theFindList, i)
  377.     put i && thisKeyword && thisWorkshopList
  378.   end repeat
  379. end
  380.  
  381.